# Copyright (C) 2008 Libresoft Research Group
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors : Israel Herraiz <herraiz@gsyc.escet.urjc.es>

import MySQLdb
import datetime

LOGFILE = "/tmp/apache_query_errors"

class MyDatabase:

    def  __init__(self, logfilename = LOGFILE):

        self.user = ''
        self.password = ''
        self.host = ''
        self.name = ''
        self.logfilename = logfilename

        self.connection = None
        self.cursor_get = None
        self.cursor_set = None


    def __writeToLog(self,text):
        logfile = open(self.logfilename,'a')
        content = datetime.datetime.now().isoformat(' ')
        content += ' *** '+text
        content += '\n'
        logfile.write(content)
        logfile.close()
        print "ERROR: CHECK LOG"
        
    def connect(self):
        self.connection = MySQLdb.connect(user = self.user,
                                          passwd = self.password,
                                          host = self.host,
                                          db = self.name)

        self.cursor_get = self.connection.cursor()
        self.cursor_set = self.connection.cursor()

